$(document).ready(function(){
	//external
    $('a[rel="external"]').attr('target', '_blank');
	
	// menu
	jQuery("ul.wd-dropdownMenu li").hover(function(){
		jQuery(this).find('ul:first').css({visibility:"visible",display:"none"}).show(200);
		},function(){
		jQuery(this).find('ul:first').css({visibility:"hidden"});
	});
	/*Rule Hover*/
	var $timeMenuId = null;
	var menuCloseFlag = true;
	jQuery("ul.wd-dropdownMenu ul.wd-categorymenu").mouseout(function(){
		var self = this;
		menuCloseFlag = true;
		setTimeout(function(){
			if(menuCloseFlag){
				jQuery(self).parent().find("a:first").removeClass("hover-rule");
			}
		},200);	
	});
	jQuery("ul.wd-dropdownMenu ul.wd-categorymenu").mouseover(function(){
		menuCloseFlag = false;
		jQuery(this).parent().find("a:first").addClass("hover-rule");
	});
	jQuery("ul.wd-dropdownMenu ul.wd-categorymenu ul").mouseover(function(){
		menuCloseFlag = false;
		jQuery(this).parent().find("a:first").addClass("wd-hover-rule-1");
		jQuery(this).parent().parent().parent().find("a:first").addClass("hover-rule");
	});
	jQuery("ul.wd-dropdownMenu ul.wd-categorymenu ul").mouseout(function(){
		var self = this;
		menuCloseFlag = true;
		setTimeout(function(){
			if(menuCloseFlag){
				jQuery(self).parent().find("a:first").removeClass("wd-hover-rule-1");
				jQuery(self).parent().parent().parent().find("a:first").removeClass("hover-rule");
			}
		},200);	
	});
	// menu .end
	//wd-nav-sub-vertical
	var _navForRPW = $('.wd-nav-vertical');
	var _buttonRPW = _navForRPW.find('a.wd-button-nav');
	_buttonRPW.click(function(){
		$('ul.wd-nav-sub-vertical').slideToggle();
		return false;
	});
	$( '.wd-nav-vertical ul.wd-nav-sub-vertical li.arrow-down > ul' )
		.hide()
		.click(function( e ){
			e.stopPropagation();
	});
	_buttonRPW.bind('click',function(e){
			e.stopPropagation();
			$(document).bind('click',function(){$('.wd-nav-vertical ul.wd-nav-sub-vertical').slideUp(500);});
		});
	$('.wd-nav-vertical ul.wd-nav-sub-vertical > li.arrow-down').toggle(function(){
	  $(this).find('ul').slideDown(500);
	}, function(){
		$(this).find('ul').slideUp(500);
	});
	//wd-nav-sub-vertical .end
	//banner
	$('.flexslider').flexslider({
		animation: "slide",
		start: function(slider){
		  $('body').removeClass('loading');
		},
		touch: true,
		move: 0
	});
	//banner .end

	//download document
	var _this = $(".wd-block-new-content");
	var _thisDownloadBT = _this.find(".wd-download-bt");
	var _listDownload = _this.find(".list-documents");
	_thisDownloadBT.click(function(){
		_listDownload.slideToggle();
	});

	//left menu more
	var _hasChild = $(".wd-list-link-more").find(".haschild");
	_hasChild.find('.sub-category').hide();
	_hasChild.each(function(){ 
		$(this).click(function(){
			$(this).find(".arrow-dropdown").toggleClass("arrow-dropdown-active");
			$(this).find(".sub-category").slideToggle();
		});
	});

	//zoom map
	$('.zoommap').smoothZoom();
    
	function imageViewport(classDiv){
		var $div = $(classDiv);
		var $img = $(classDiv).find('img');
		$img.css({'position':'absolute','left':'0'});
		$div.mousemove(function(event) {
			var xPos = event.pageX;
			var yPos = event.pageY;
			var divW = $div.width();
			var imgW = $img.width() - divW;
			var divH = $div.height();
			var imgH = $img.height() - divH;
			var x = Math.min(imgW, xPos / divW * imgW);
			var y = Math.min(imgH, yPos / divH * imgH);
			TweenLite.to($img, .5, {css:{left: (-x) + 'px', top: (-y) + 'px'}});
		});
	}
	imageViewport('.js-bg-image');
        var href_main= document.location.href;
    if(href_main.indexOf('/project') != -1){
         $('#wd-nav li:nth-child(1) a').addClass("wd-current");
         $('#wd-nav .wd-categorymenu a').removeClass("wd-current");
         
    }  
    if(href_main.indexOf('/phase') != -1){
         $('#wd-nav li:nth-child(2) a').addClass("wd-current");
         $('#wd-nav .wd-categorymenu a').removeClass("wd-current");
    } 
    if(href_main.indexOf('/location') != -1){
         $('#wd-nav li:nth-child(3) a').addClass("wd-current");
         $('#wd-nav .wd-categorymenu a').removeClass("wd-current");
    } 
    if(href_main.indexOf('/news') != -1){
         $('#wd-nav li:nth-child(4) a').addClass("wd-current");
         $('#wd-nav .wd-categorymenu a').removeClass("wd-current");
    }  
    if(href_main.indexOf('/contact') != -1){
         $('#wd-nav li:nth-child(5) a').addClass("wd-current");
         $('#wd-nav .wd-categorymenu a').removeClass("wd-current");
    }         
});